package com.cyp.interviewservice.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cyp.interviewservice.entity.InterviewQuestion;
import com.cyp.interviewservice.service.InterviewQuestionService;
import io.micrometer.common.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RequestMapping("/api/interview-questions")
@RestController
public class InterviewController {

    @Autowired
    private InterviewQuestionService interviewService;
    @RequestMapping
    public String getAllInterviewQuestions() {
        return "success";
    }

    /**
     *  查询面试题
     * @param category fenlei
     * @param question  根据题目模糊查询
     * @return
     */
    @GetMapping("/list")
    public IPage<InterviewQuestion> getInterviewQuestionsByCategory(String  category,String question){
        Page<InterviewQuestion> page = Page.of(1, 20);
        interviewService.getBaseMapper().selectPage(page, new QueryWrapper<InterviewQuestion>()
                .eq("category", category)
                .like(StringUtils.isNotBlank( question), "question", question));
        return page;
    }
}
